package tjs.study.notes.base.arthas;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tjs.study.notes.base.arthas.service.ArthasService;

import java.util.Random;

/**
 * Created by Nicky.Tang on 2023/5/30 下午10:14
 *
 * @since 02.12.10
 */
@RestController
@RequestMapping
public class Arthas {
    /**
     * idea启动无法监听，需要使用java -jar监听: java -jar tjs-study-base-0.0.1-SNAPSHOT.jar
     * # tt 
     *  tt  -t tjs.study.notes.base.arthas.Arthas * '#cost > 200' >> ./arthas_dev.log &  
     *  tt  -t tjs.study.notes.base.arthas.service.* * '#cost > 200' >> ./arthas_dev.log &
     * ## 排序找出耗时前10的
     *  sort -k 4nr arthas_dev.log | head -n 10 
     *  
     * # trace
     *  trace -E tjs.study.notes.base.arthas.Arthas|tjs.study.notes.base.arthas.service.ArthasService .* -n 50  '#cost > 200'
     */
    @GetMapping("/dev/arthas")
    public String doTest() throws InterruptedException {
        return test("ww");
    }
    

    public static String test(String param) throws InterruptedException {
        for (int i = 0; i < 3; i++) {
            Arthas.test2(i);
            ArthasService.testService(i);
        }
        System.out.println("结束");
        return "aa";
    }

    public static String test2(int param) throws InterruptedException {
        Thread.currentThread().sleep(new Random().nextInt(10) * 100);
        System.out.println("aa" + param);
        return "aa" + param;
    }

}
